<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <h2>{{title}}</h2>
    <h2>{{title1}}</h2>
    <ul v-for="(item, index) in this.list" :key="index">
      <li>{{item.name}}</li>
    </ul>
      <button @click="regist">regist</button>
      <button @click="login">login</button>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'Home',
  data(){
    return{
      title:'',
      title1:'',
      list:[]
    }
  },
  created(){
    // this.get1();
    // this.get2();
    // this.post1();
    // this.regist();
  },
  methods:{
    regist(){
      axios({
        url:'http://49.235.98.65:3000/user/regist',
        method:'POST',
        data:{//请求的时候发送的参数
          username:'2323',
          password:'23232323',
          school:'qwqw',
          nickname:'as',
          age:12,
          gender:0
        }
        }).then( res => {
          console.log(res)
        }).catch( err => {
          console.log(err)
        })
    },
    login () {
      axios ({
        url:'http://49.235.98.65:3000/user/login',
        method:'POST',
        data:{
          username:'111',
          password:"222",
        }
        }).then( res => {
          console.log(res)
        }).catch( err => {
          console.log(err)
        })
    },

    post1(){
      axios({
        url:'http://192.168.10.123:9999/user/list',
        method:'POST',
        headers: {
          token:'1111'
        } ,
        data:{
          page:1,//页
          size:3,//多少条
        }
      })
      .then( res => {
        console.log(res)
       this.list =  res.data
      })
      .catch( err => {
        console.log(err)
        // console.log('2222')
      })
    },
    get1(){
      axios.get('http://192.168.10.123:9999/path1',{
        params:{//带参数请求第二个参数 params也是一个对象 括号里面才是请求的具体参数
          id:12
        }
      }).then( res => {//用函数来接收返回体
       // axios.post('')
        console.log(res);
        console.log(res.data.title);
        this.title = res.data.title;
      }).catch( err => {
        console.log(err);
      })
    },
    get2(){
      axios({
        url:'http://192.168.10.123:9999/path2',
        method:'GET',
        params:{
          id:12,
        }
      }).then( (res) =>{
        this.title1 = res.data.title;
          console.log(res)
      }).catch( (err) =>{
          console.log(err)
      })
    },
    
  }
}
</script>
